package com.industrial.app.controller.formal;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.industrial.app.domain.formal.BizIndustryAddedFormal;
import com.industrial.app.service.IBizIndustryAddedFormalService;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 分行业工业增加值同比Controller
 * 
 * @author ruoyi
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/biz/formal/added")
public class BizIndustryAddedFormalController extends BaseController
{
    @Autowired
    private IBizIndustryAddedFormalService bizIndustryAddedFormalService;

    /**
     * 查询分行业工业增加值同比列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizIndustryAddedFormal bizIndustryAddedFormal)
    {
        if(StringUtils.isNotBlank(bizIndustryAddedFormal.getDates())){
            DateTime datesTimes= DateUtil.parse(bizIndustryAddedFormal.getDates(),"yyyy年MM月");
            bizIndustryAddedFormal.setDates(DateUtil.format(datesTimes,"yyyy-MM"));
        }else{
             throw new RuntimeException("未指定日期！");
        }
        startPage();
        List<BizIndustryAddedFormal> list = bizIndustryAddedFormalService.selectBizIndustryAddedFormalList(bizIndustryAddedFormal);
        return getDataTable(list);
    }

    /**
     * 导出分行业工业增加值同比列表
     */
//    @PreAuthorize("@ss.hasPermi('addedFormal:formal:export')")
//    @Log(title = "分行业工业增加值同比", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizIndustryAddedFormal bizIndustryAddedFormal)
    {
        List<BizIndustryAddedFormal> list = bizIndustryAddedFormalService.selectBizIndustryAddedFormalList(bizIndustryAddedFormal);
        ExcelUtil<BizIndustryAddedFormal> util = new ExcelUtil<BizIndustryAddedFormal>(BizIndustryAddedFormal.class);
        util.exportExcel(response, list, "分行业工业增加值同比数据");
    }

    /**
     * 获取分行业工业增加值同比详细信息
     */
//    @PreAuthorize("@ss.hasPermi('addedFormal:formal:query')")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizIndustryAddedFormalService.selectBizIndustryAddedFormalByBaseId(baseId));
    }

    /**
     * 新增分行业工业增加值同比
     */
//    @PreAuthorize("@ss.hasPermi('addedFormal:formal:add')")
//    @Log(title = "分行业工业增加值同比", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizIndustryAddedFormal bizIndustryAddedFormal)
    {
        return toAjax(bizIndustryAddedFormalService.insertBizIndustryAddedFormal(bizIndustryAddedFormal));
    }

    /**
     * 修改分行业工业增加值同比
     */
//    @PreAuthorize("@ss.hasPermi('addedFormal:formal:edit')")
//    @Log(title = "分行业工业增加值同比", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizIndustryAddedFormal bizIndustryAddedFormal)
    {
        return toAjax(bizIndustryAddedFormalService.updateBizIndustryAddedFormal(bizIndustryAddedFormal));
    }

    /**
     * 删除分行业工业增加值同比
     */
//    @PreAuthorize("@ss.hasPermi('addedFormal:formal:remove')")
//    @Log(title = "分行业工业增加值同比", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizIndustryAddedFormalService.deleteBizIndustryAddedFormalByBaseIds(baseIds));
    }

    /**
     * <p>
     *     查询APP左上角的日期数据
     * </p>
     * @return 日期的集合
     */
    @GetMapping("/getUniqueDatesFromDatabase")
    public AjaxResult getUniqueDatesFromDatabase(){
        List<String> dateArgs = bizIndustryAddedFormalService.getUniqueDatesFromDatabase();
        return AjaxResult.success(dateArgs);
    }
}
